#include<iostream>
#include<queue>
using namespace std;
struct TreeNode {
     int val;
     TreeNode *left;
     TreeNode *right;
     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 };
 class Solution {
public:
    int maxDepth(TreeNode* root) {
        if (root == NULL)return 0;
        queue<TreeNode*>q;
        q.push(root);
        int level = 0;
        while (!q.empty())
        {
            int size = q.size();
            for (int i = 0; i < size; i++)
            {
                TreeNode *cur = q.front();
                q.pop();
                if(cur->left != NULL) q.push(cur->left);
                if(cur->right!=NULL) q.push(cur->right);
            }
            level++;
        }
        return level;
    }
};